<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  
  <div id="root">
    <laoda></laoda>
    
    <laoer></laoer>
  </div>

  <script src="./libs/vue.js"></script>
  <script>

    const bus = new Vue()

    new Vue({
      el: '#root',
      components: {
        'laoda': {
          template: `
            <div>
              我是老大
              <button @click="handler">打钱</button>
            </div>
          `,
          methods: {
            handler() {
              bus.$emit('getmoney')
            }
          }
        },
        'laoer': {
          template: `
            <div>
              我是老二
              <span v-if='seen'>666</span>
            </div>
          `,
          data() {
            return {
              seen: false
            }
          },
          created() {
            bus.$on('getmoney', () => {
              console.log('老二存钱')
              this.seen = true
            })
          }
        }
      }
    })
  </script>

</body>
</html>